/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hcsc.datapower.CMDB.gui;

import com.hcsc.datapower.CMDB.common.AuthUser;
import com.hcsc.datapower.CMDB.service.MainApplicationWindowController;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *
 * @author I307211
 */
public class MainApplicationWindow extends JFrame {

    private MainApplicationWindowController mainapplicationwindowcontroller;
    /**
     * Creates new form MainApplicationWindow
     */
    public MainApplicationWindow() {
        initComponents();
        //center the window
        setLocationRelativeTo(null);
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jButton_search = new javax.swing.JButton();
        jButton_configuration = new javax.swing.JButton();
        jButton_exit = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1_file = new javax.swing.JMenu();
        jMenuItem1_exit = new javax.swing.JMenuItem();
        jMenu2_edit = new javax.swing.JMenu();
        jMenu_Admin = new javax.swing.JMenu();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem1_addusermenu = new javax.swing.JMenuItem();
        jMenuItem2_editusermenu = new javax.swing.JMenuItem();
        jMenuItem_vendors = new javax.swing.JMenuItem();
        jMenuItem_ports = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Welcome"));

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 392, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 100, Short.MAX_VALUE)
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Wizard"));

        jButton1.setText("New Service");

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jButton1)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jButton1)
                .addContainerGap(121, Short.MAX_VALUE))
        );

        jButton_search.setText("Search");
        jButton_search.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_searchActionPerformed(evt);
            }
        });

        jButton_configuration.setText("Configuration");
        jButton_configuration.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_configurationActionPerformed(evt);
            }
        });

        jButton_exit.setText("Exit");
        jButton_exit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_exitActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jButton_search)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jButton_configuration)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jButton_exit))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(jButton_search)
                .add(jButton_configuration)
                .add(jButton_exit))
        );

        jMenu1_file.setText("File");

        jMenuItem1_exit.setText("Exit");
        jMenuItem1_exit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1_exitActionPerformed(evt);
            }
        });
        jMenu1_file.add(jMenuItem1_exit);

        jMenuBar1.add(jMenu1_file);

        jMenu2_edit.setText("Edit");
        jMenuBar1.add(jMenu2_edit);

        jMenu_Admin.setText("Admin");

        jMenu3.setText("Users");

        jMenuItem1_addusermenu.setText("Add User");
        jMenuItem1_addusermenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1_addusermenuActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem1_addusermenu);

        jMenuItem2_editusermenu.setText("Edit User");
        jMenuItem2_editusermenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2_editusermenuActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem2_editusermenu);

        jMenu_Admin.add(jMenu3);

        jMenuItem_vendors.setText("Vendors");
        jMenuItem_vendors.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_vendorsActionPerformed(evt);
            }
        });
        jMenu_Admin.add(jMenuItem_vendors);

        jMenuItem_ports.setText("Ports");
        jMenuItem_ports.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_portsActionPerformed(evt);
            }
        });
        jMenu_Admin.add(jMenuItem_ports);

        jMenuBar1.add(jMenu_Admin);

        setJMenuBar(jMenuBar1);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jPanel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_searchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_searchActionPerformed
        // TODO add your handling code here:
        //MainAppWindowController cont = (MainAppWindowController)getAppController();
        //cont.initSearchWindow();
        JOptionPane.showMessageDialog(this, "Eggs are not supposed to be green.");
        
    }//GEN-LAST:event_jButton_searchActionPerformed

    private void jButton_exitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_exitActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_jButton_exitActionPerformed

    private void jButton_configurationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_configurationActionPerformed
       getMainapplicationwindowcontroller().initConfigWindow();
    }//GEN-LAST:event_jButton_configurationActionPerformed

    private void jMenuItem1_exitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1_exitActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jMenuItem1_exitActionPerformed

    private void jMenuItem_vendorsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_vendorsActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem_vendorsActionPerformed

    private void jMenuItem_portsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_portsActionPerformed
        // TODO add your handling code here:
         getMainapplicationwindowcontroller().initUserAdminMenu(true);
    }//GEN-LAST:event_jMenuItem_portsActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
        setAdmin(AuthUser.hasAdminAccess());
    }//GEN-LAST:event_formWindowOpened

    private void jMenuItem1_addusermenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1_addusermenuActionPerformed
        // TODO add your handling code here:
        getMainapplicationwindowcontroller().initUserAdminMenu(true);
        
    }//GEN-LAST:event_jMenuItem1_addusermenuActionPerformed

    private void jMenuItem2_editusermenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2_editusermenuActionPerformed
        // TODO add your handling code here:
        //getMainapplicationwindowcontroller().initUserAdminMenu(false);
    }//GEN-LAST:event_jMenuItem2_editusermenuActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton_configuration;
    private javax.swing.JButton jButton_exit;
    private javax.swing.JButton jButton_search;
    private javax.swing.JMenu jMenu1_file;
    private javax.swing.JMenu jMenu2_edit;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1_addusermenu;
    private javax.swing.JMenuItem jMenuItem1_exit;
    private javax.swing.JMenuItem jMenuItem2_editusermenu;
    private javax.swing.JMenuItem jMenuItem_ports;
    private javax.swing.JMenuItem jMenuItem_vendors;
    private javax.swing.JMenu jMenu_Admin;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    // End of variables declaration//GEN-END:variables

    public void setAdmin(boolean admin){
        jMenu_Admin.setEnabled(admin);
        jMenu_Admin.setVisible(admin);
    }

    public MainApplicationWindowController getMainapplicationwindowcontroller() {
        return mainapplicationwindowcontroller;
    }

    @Autowired
    public void setMainapplicationwindowcontroller(MainApplicationWindowController mainapplicationwindowcontroller) {
        this.mainapplicationwindowcontroller = mainapplicationwindowcontroller;
    }

}
